package com.coocaa.ccmvp.demo.p;

import android.support.test.rule.ActivityTestRule;

import com.coocaa.ccmvp.MainActivity;
import com.coocaa.ccmvp.demo.m.DemoModel;
import com.coocaa.ccmvp.demo.m.IDemoModel;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;

/**
 * Created by lu on 17-2-7.
 */

@RunWith(JUnit4.class)
public class IDemoPresenterTest {
    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);

    private IDemoPresenter presenter = null;

    @Before
    public void setUp() throws Exception {
        presenter = new DemoPresenter();
        presenter.create(mActivityRule.getActivity());
    }

    @Test
    public void performLogin() throws Exception {
        IDemoModel demoModel = Mockito.mock(DemoModel.class);
        presenter.attachModel(demoModel);
        String name = "name_123321";
        String passwd = "passwd_123321";

        Mockito.when(demoModel.isLogin(name)).thenReturn(false);
        presenter.login(name, passwd);
        Mockito.verify(demoModel).isLogin(name);
        Mockito.verify(demoModel).login(name, passwd);
    }

    @Test
    public void performAlreadyLogin() throws Exception {
        IDemoModel demoModel = Mockito.mock(DemoModel.class);
        presenter.attachModel(demoModel);
        String name = "name_123321";
        String passwd = "passwd_123321";

        Mockito.when(demoModel.isLogin(name)).thenReturn(true);
        presenter.login(name, passwd);
        Mockito.verify(demoModel).isLogin(name);
    }
}
